<?php

function address_unit_value_editor($address_unit_value_infos)
{/*{{{*/
    $template = '';

    foreach ($address_unit_value_infos as $address_unit_value_id => $address_unit_value_info) {

        $child_add_string = '';
        $child_unit_turn_id = '';
        $child_unit_name = '';

        if (isset($address_unit_value_info['nodes'])) {

            $child_add_string = '[添加'.$address_unit_value_info['child_unit']->name.']';
            $child_unit_turn_id = $address_unit_value_info['child_turn']->id;
            $child_unit_name = $address_unit_value_info['child_unit']->name;
        }

        $template .= sprintf('
            <div class="%s show">
                <div class="title">%s</div>
                <div class="editBT"></div>
                <!--div class="editArea"><span>[编辑]</span><span>[添加%s]</span><span>%s</span><span>[删除]</span></div-->
            </div>
            <div class="Row" child-unit-turn-id="%s" child-unit-name="%s">', 
            isset($address_unit_value_info['nodes'])?'ParentNode':'ChildNode',
            $address_unit_value_info['value']->value.' '.$address_unit_value_info['unit']->name,
            $address_unit_value_info['unit']->name,
            $child_add_string,
            $child_unit_turn_id,
            $child_unit_name
        );

        if (isset($address_unit_value_info['nodes'])) {

            $template .= call_user_func(__FUNCTION__, $address_unit_value_info['nodes']);
        }

        $template .= '</div>';
    }

    return $template;
}/*}}}*/
